<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->member_status;
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=trim($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_aiagent_member',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'客户池'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'createtime','title'=>'注册时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		)
	);
	$return['sex']=array('未知','男','女');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_aiagent_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$item['member']=cfc('core')->member_show($item['mid']);
	$item['title']=$item['title']?:$item['member']['nickname'];
    $return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edit'=>array(
			array('name'=>'title','title'=>'昵称','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
		)
	);
	$return['sex']=array('未知','男','女');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('昵称不能为空！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'sex'=>trim($postdata['sex']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_aiagent_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_aiagent_member',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_aiagent_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_aiagent_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>